package com.woniu.adopt.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.adopt.entity.PetArticle;
import com.woniu.adopt.mapper.PetArticleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PetArticleService {
    @Autowired
    PetArticleMapper petArticleMapper;

    public PageInfo<PetArticle> queryByPage(int pageNum, int pageSize, String title) {
        PageHelper.startPage(pageNum, pageSize);
        List<PetArticle> petArticles = petArticleMapper.selectByConf(title);
        return new PageInfo<>(petArticles);
    }

    public int updateViews(int id) {
        return petArticleMapper.updateViews(id);

    }

    public PetArticle queryById(int id) {
        return petArticleMapper.selectByPrimaryKey(id);
    }

    public int modifyById(int id, String title, String image, String introduce, String body, int display) {
        return petArticleMapper.updataById(id, title, image, introduce, body, display);
    }

    public int add(PetArticle petArticle) {
        return petArticleMapper.insert(petArticle);
    }

    public int removeByid(int id) {
        return petArticleMapper.deleteByPrimaryKey(id);
    }
}
